const WXAPI = require('apifm-wxapi')
Page({
  data: {
    footer_img: wx.getStorageSync('footer_img'),
    sphid: wx.getStorageSync('sphid'),
    index_video1: wx.getStorageSync('index_video1'),
    index_img1: wx.getStorageSync('index_img1'),
    index_img2: wx.getStorageSync('index_img2'),
    index_img3: wx.getStorageSync('index_img3'),
    defaultBanners: [],
    category: [],
    like_img: [],
    like:[],
    id:"",
    shuju:"",
  },
  onLoad: function (options) {
    const that = this;
    that.setData({
      id: options.id,
      footer_img: wx.getStorageSync('footer_img'),
      sphid: wx.getStorageSync('sphid'),
      index_video1: wx.getStorageSync('index_video1'),
      index_img1: wx.getStorageSync('index_img1'),
      index_img2: wx.getStorageSync('index_img2'),
      index_img3: wx.getStorageSync('index_img3'),
    });
    that.detail();
  },



 
  onShow: function () {

  },


    // 点击图片放大
    imgYu:function(event){
      var src = event.currentTarget.dataset.src;//获取data-src
      var imgList = this.data.gdtp;//获取data-list
      console.log(imgList);
      //图片预览
      wx.previewImage({
          current: src, // 当前显示图片的http链接
          urls: imgList // 需要预览的图片http链接列表
      })
  },



  detail(e){
   
    let that = this;
    WXAPI.goodsDetail(that.data.id).then(function(res) {
      if (res.code == 0) {
          console.log("spxx:",res.data);
          that.setData({
              gdtp:res.data.pics2,
              shuju:res.data,
          })
          that.getlike(res.data.basicInfo.categoryId)
          wx.setNavigationBarTitle({
             title: res.data.basicInfo.name,
          })
      }
    })
 },




  // 获取最新作品
  // priceUp 价格升序，priceDown 价格倒序，ordersUp 销量升序，ordersDown 销量降序, sellsDown 商品销售数量降序排，addedUp 发布时间升序，addedDown 发布时间倒序, nameUp 商品名称升序, useful 点赞最多， dateEndAsc 即将结束的最考前；dateEndDesc 停售时间最大的越靠前; storesAsc 库存升序； storesDesc 库存倒序; goodReputation 好评多, views 浏览量
  async getlike(e) {
    var that = this;
    await WXAPI.goods({
      categoryId:e,
      page: 1,
      pageSize: 8,
      orderBy: 'addedDown',
    }).then(function (res) {
      if (res.code == 0) {
        that.setData({
          like_img: res.data
        });
      }
    })
  },

  //跳转到列表页面
  toList: function (t) {
    var a = t.currentTarget.dataset.categoryid;
    wx.navigateTo({
      url: "/pages/a1_list/index?categoryId=" + a
    })
  },

  //点击其他作品
  toPost: function (t) {
    let that = this
    var a = t.currentTarget.dataset.postid;
    that.setData({
      id: a,
    });
    that.detail();
  },

  //跳转到a2页面
  toA2: function () {
    wx.switchTab({
      url: '/pages/a2/index',
    });
  },



  // 点击幻灯片
  gotoBannerLink: function (t) {
    var a = t.currentTarget.dataset.link;
    console.info("open link", a), a && (a.includes("https://mp.weixin.qq.com")) && wx.navigateTo({
      url: "/pages/webview/webview?link=" + a
    });
  },

  //拨打电话
  callPhone() {
    wx.makePhoneCall({
      phoneNumber: wx.getStorageSync('phone')
    })
  },

  // 打开视频号主页
  toVideo() {
    wx.openChannelsUserProfile({
      finderUserName: wx.getStorageSync('sphid'),
    });
  },


  onShareAppMessage() { console.log(111);},
  onShareTimeline() { },


    handleShareClick_hy() {
      wx.showShareMenu({ // 显示默认的分享菜单
        withShareTicket: true,
        menus: ['shareAppMessage',], // 分享给朋友和分享到朋友圈
      })
    },

    handleShareClick_pyq() {
      wx.showShareMenu({ // 显示默认的分享菜单
        withShareTicket: true,
        menus: ['shareTimeline'], // 分享给朋友和分享到朋友圈
      })
    }


})